<template>
    <div>
        <el-dialog title="添加党员培训" :visible.sync="dialogVisible" width='450px' append-to-body v-dialogDrag :close-on-click-modal="false" >
            <div>
                <el-form ref="rowdata" :model="rowdata" label-width="100px" class="personeditform" :rules="rules" status-icon>
                    <el-form-item label="年份" >
                        <el-input v-model="rowdata.year" style="width: 80%;" :disabled="true"></el-input>
                    </el-form-item>
                    <el-form-item label="培训单位"   prop="pxdw">
                        <el-input v-model="rowdata.pxdw" style="width: 80%;" ></el-input>
                    </el-form-item>
                    <el-form-item label="培训时间"   prop="pxtime">
                        <el-date-picker v-model="rowdata.pxtime" type="date" placeholder="" value-format="yyyy-MM-dd"  style="width: 80%;"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="参训人员"   prop="persons">
                         <el-input type="textarea" autosize placeholder="" v-model="rowdata.persons" style="width: 80%;"></el-input>
                    </el-form-item>
                    <el-form-item label="培训内容"   prop="pxnr">
                        <el-input v-model="rowdata.pxnr" style="width: 80%;" ></el-input>
                    </el-form-item>
                </el-form>
                <el-row style="position: relative;width: 100%;">
                    <el-button style="margin: 0 auto;display: block;"  type="primary" @click="checksubmit('rowdata')">确定并保存<i class="el-icon-upload el-icon--right" ></i></el-button>
                </el-row>
            </div>
        </el-dialog>
    </div>
</template>
<script>
    import {mapActions} from 'vuex';
    export default {
        data() {
            return { 
                dialogVisible: false, 
                rowdata:{
                    year:'',
                    pxdw:'',
                    pxtime:'',
                    persons:'',
                    pxnr:'',
                },
                rules: {
                    pxdw: [{ required: true, message: '不能为空', trigger: 'blur' }],
                    pxtime: [{ required: true, message: '不能为空', trigger: 'blur' }],
                    persons: [{ required: true, message: '不能为空', trigger: 'blur' }],
                    pxnr: [{ required: true, message: '不能为空', trigger: 'blur' }],
                },
            };
            
        },
        mounted() {
            
        },
        components: {},
        watch: {
            dialogVisible: function (n) {
                if (n == true) {
                    this.rowdata.pxdw='';
                    this.rowdata.pxtime='';
                    this.rowdata.persons='';
                    this.rowdata.pxnr='';
                }
            },
        },
        methods: {
            checksubmit(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.uploadAjax();
                    }
                    else {
                        this.$message("请填写必要信息");
                        return false;
                    }
                });
            },
            uploadAjax(){
                let _this=this;
                this.rowdata.dwid=this.$store.state.Dw_DzbID.dwid;
                this.rowdata.dzbid=this.$store.state.Dw_DzbID.dzbid;
                let postdata={
                    type:"adddypx",
                    split:JSON.stringify(this.rowdata)
                }
                this.$Common.AjaxPost(postdata,true)
                .then(function(e){
                    _this.$message("操作成功");
                    _this.dialogVisible=false;
                    _this.$emit('editResult');
                },function(){
                     _this.$message("操作失败");
                })
                .catch(function(reason) {
                    console.log('catch:', reason);
                });
            },
        },
    }
</script>·